package com.kaifamiao.convert;

import java.time.*;
import java.util.Date;

public class DateToZonedDateTime {

    public static void main(String[] args) {

        Date date = new Date();

        // Date ---> Instant
        Instant instant = date.toInstant();

        ZoneId zone = ZoneOffset.of( "+08:00" );
        // Instant ---> ZonedDateTime
        ZonedDateTime zdt = ZonedDateTime.ofInstant( instant, zone );
        System.out.println( zdt );

        // ZonedDateTime ---> LocalDateTime
        LocalDateTime dt = zdt.toLocalDateTime();
        System.out.println( dt );

        // ZonedDateTime ---> LocalDate
        LocalDate localDate = zdt.toLocalDate();
        System.out.println( localDate );

        // ZonedDateTime ---> LocalTime
        LocalTime localTime = zdt.toLocalTime();
        System.out.println( localTime );
    }

}
